package cn.tedu.util;

import java.util.ArrayList;
import java.util.LinkedList;

//测试 ArrayList和LinkedList的查询效率
public class Test2 {
    public static void main(String[] args) {
        //        method();//ArrayList查的快2ms
        method2();//LinkedList查的慢3824ms
    }
    //LinkedList查
    public static void method2() {
        LinkedList<Integer> list = new LinkedList();
        for (int i = 0; i < 100000; i++) {
            list.add(i);
        }
        //查
        long start = System.currentTimeMillis();//计时开始
        for (int i = 0; i < list.size(); i++) {
            //根据下标i获取数据
            Integer data = list.get(i);
        }
        long end = System.currentTimeMillis();//计时结束
        System.out.println(end-start);//3824ms
    }
    //ArrayList查
    public static void method() {
        ArrayList<Integer> list = new ArrayList();
        for (int i = 0; i < 100000; i++) {
            list.add(i);
        }
        //查
        long start = System.currentTimeMillis();//计时开始
        for (int i = 0; i < list.size(); i++) {
            //根据下标i获取数据
            Integer data = list.get(i);
        }
        long end = System.currentTimeMillis();//计时结束
        System.out.println(end-start);//2ms
    }
}
